(symbols "listAsArray" 'pico)

(local
  *IntegerType
  *ObjectClass)

(setq
  *IntegerType (public "java.lang.Integer" "TYPE")
  *ObjectClass (javaClass "java.lang.Object") )

(when (>= (javaVersion T) (1 7) )
  (de pico~listAsArray (List Class)
    (if List
      (let (Length (length List)
            Array (array Class Length)
            Set (thread Array
                  constantMethodHandle
                  (composeMethodHandle
                    (java "java.lang.invoke.MethodHandles"
                      "arrayElementSetter"
                      (java Array "getClass") ) ) ) )
        (for (@Index . @Item) List
          (let @Index (dec @Index)
            (thread "java.util.concurrent.Callable"
              (functionalInterface (curry (@Index) @ @Index) )
              (functionalInterfaceAsMethodHandle *ObjectClass)
              (castMethodHandle *IntegerType)
              (composeMethodHandle Set)
              (passMethodHandle
                (thread "java.util.concurrent.Callable"
                  (functionalInterface (curry (@Item) @ @Item) )
                  (functionalInterfaceAsMethodHandle *ObjectClass)
                  (castMethodHandle (or Class *ObjectClass) ) ) )
              pico~invokeMethodHandle) ) )
        Array)
      (array Class) ) ) )